package com.线程Thread.Exercise;

public class Thread_Exercise_01 {
    public static void main(String[] args) {
        /** 在主线程里启动两个线程，
         *  一个A线程隔1秒输出 hi  输出10次
         *  另一个B线程隔3秒输出 hello  输出5次
         *
         */
        A a = new A();  //继承Thread   分配线程名Thread0
        B b = new B();  //实现Runnable  分配线程名Thread1
        Thread thread = new Thread(b);  //静态代理

        a.start();
        thread.start();
        System.out.println("主线程结束");
    }
}

/** 创建线程的两种方式 */

class A extends Thread{  //继承Thread
    @Override
    public void run() {
        int i=0;
        for (int j = 0; j < 10; j++) {
            System.out.println("A  hi"+i++);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
        System.out.println("A线程类的run方法结束");
    }
}


class B implements Runnable{  //实现Runnable
    @Override
    public void run() {
        int i=0;
        for (int j = 0; j < 5; j++) {
            System.out.println("B  Hello World"+i++);
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
        System.out.println("B线程类的run方法结束");
    }
}